package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-18
 */
@RestController
@RequestMapping("/coupons")
@Api(tags = "优惠券规则信息接口")
@RequiredArgsConstructor
public class CouponController {

    private final ICouponService couponService;
    @ApiOperation("管理端新增优惠券功能")
    @PostMapping
    public void addCoupon(@RequestBody @Validated CouponFormDTO form) {
        couponService.addCoupon(form);
    }
    @ApiOperation("管理端分页查询优惠券功能")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> queryCouponPage(CouponQuery query) {
        return couponService.queryCouponPage(query);
    }
    @ApiOperation("管理端发送优惠券功能")
    @PutMapping("/{id}/issue")
    public void issueCoupon(@PathVariable("id") Long id, @RequestBody @Validated CouponIssueFormDTO dto) {
        couponService.issueCoupon(id, dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改优惠券功能")
    public void updateCoupon(@PathVariable("id") Long id, @RequestBody @Validated CouponFormDTO dto) {
        couponService.updateCoupon(id,dto);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除优惠券功能")
    public void deleteCoupon(@PathVariable("id") Long id) {
        couponService.removeById(id);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询优惠券功能")
    public CouponDetailVO getCouponById(@PathVariable("id") Long id) {
        return couponService.queryById(id);
    }
    @PutMapping("/{id}/pause")
    @ApiOperation("暂停优惠券功能")
    public void pauseCoupon(@PathVariable("id") Long id) {
        couponService.pauseCoupon(id);
    }
    @GetMapping("/list")
    @ApiOperation("用户端查询发放中的优惠券")
    public List<CouponVO> queryCouponList() {
        return couponService.queryCouponList();
    }
}
